#include <iostream>
#include <map>

using namespace std;
const int N = 1e3 + 5;
int prime[N], d, X[N], P[N];
bool isp[N];
void getprime() {
    for (int i = 2; i < N; ++ i) {
        if (!isp[i]) prime[d ++] = i;
        for (int j = 0; prime[j] * i < N; ++ j) {
            isp[i * prime[j]] = true;
            if (i % prime[j] == 0) break;
        }
    }
}
static int MOD = []() {
    ios::sync_with_stdio(false);
    cin.tie(0), cout.tie(0);
    return 1e9 + 7;
}();
long long ipow(long long x, int p) {
    x %= MOD;
    long long res = 1;
    while (p) {
        if (p & 1) res = res * x % MOD;
        x = x * x % MOD;
        p >>= 1;
    }
    return res;
}
int tr[105][N];
void add(int trr[], int i) {
    for ( ; i < N; i += i & -i) trr[i] ++;
}
int check(int trr[], int i) {
    int res = 0;
    for ( ; i > 0; i -= i & -i) res += trr[i];
    return res;
}
signed main() {
    int n, k;
    //getprime();
    cin >> n >> k;
    int t;
    while (cin >> t) {
        int g;
        if (t == 1) {
            cin >> g;
            for (int i = 1; i <= g; ++ i) {
                int a, b;
                cin >> a >> b;
                add(tr[a], b);
            }
        } else {
            int a, l, r;
            cin >> a >> l >> r;
            cout << check(tr[a], r) - check(tr[a], l - 1) << endl;
        }
    }
    return 0;
}